<template>
    <q-page class="cc-admin">

        <div class="col bg-white shadow-2 q-pa-md q-ma-sm">
            <q-table flat color="primary" class="cross_table" separator="cell" :columns="columns" :data="list" row-key="id" :pagination.sync="pagination" :visible-columns="group" @request="query" :rows-per-page-options="[10, 20, 50, 100]" selection="multiple" :selected.sync="selected">

                <template v-slot:top="">
                    <div class="row no-wrap full-width">
                        <q-input clearable outlined dense placeholder="请输入关键字搜索" class="on-left" @input="query" debounce="500" v-model="key">
                            <template #append>
                                <q-btn flat round icon="search" color="primary" @click="query" :loading="loading">
                                    <q-tooltip>搜索</q-tooltip>
                                </q-btn>
                            </template>
                        </q-input>
                        <q-space />
                        <div class="q-gutter-xs" style="margin-left: 10px">
                            <q-btn icon="mdi-file-search-outline" no-wrap color="primary" label="查看错题分布" @click="viewEcharts" />
                        </div>
                    </div>
                </template>
                <template #body-cell-question="props">
                    <q-td :props="props" :auto-width="true">
                        <div v-html="renderMath(props.row.question)"></div>
                    </q-td>
                </template>
                <template #body-cell-opt="props">
                    <q-td :props="props" :auto-width="true">
                        <q-btn flat round dense color="primary" icon="edit" @click="edit(props.row)"> <q-tooltip>编辑</q-tooltip></q-btn>

                        <btn-del label="填空题" @confirm="del(props.row)" />
                    </q-td>
                </template>
            </q-table>
        </div>
        <q-dialog maximized flat persistent ref="dialog">
            <q-form @submit="submit" class="dialog_card column">
                <h5 class="view_title justify-between q-px-md">
                    {{ editType }}填空题
                    <q-btn dense outline round icon="clear" size="sm" v-close-popup />
                </h5>
                <q-scroll-area class="col">
                    <div class="row q-col-gutter-x-md dialog_form q-pa-md">
                        <!-- <div class="col-4">
                            <q-select v-model="form.categorys" :options="categoryOptions" clearable multiple label="请选择分类" />
                        </div> -->
                        <div class="col-12">
                            <h5>题目：</h5>
                            <!-- <q-input outlined dense v-model="form.question" type="text" /> -->
                            <div v-html="renderMath(form.question)" style="line-height: 300%;"></div>

                        </div>
                        <div class="col-12">
                            <h5>你的作答：</h5>
                            <!-- <q-input outlined dense v-model="form.answer" type="text" /> -->
                            <div v-html="renderMath(form.studentAnswer)" style="line-height: 300%;"></div>

                        </div>
                        <div class="col-12">
                            <h5>答案：</h5>
                            <!-- <q-input outlined dense v-model="form.answer" type="text" /> -->
                            <div v-html="renderMath(form.answer)" style="line-height: 300%;"></div>

                        </div>
                        <div class="col-12">
                            <h5>解析：</h5>
                            <!-- <q-input outlined dense v-model="form.analysis" type="textarea" /> -->
                            <div v-html="renderMath(form.analysis)" style="line-height: 300%;"></div>

                        </div>
                        <!-- <div class="col-12" v-if="!form.viedoUrl">
                            <h5>文件上传：</h5>
                            <q-uploader url="http://127.0.0.1:9008/weather-api/upload" :headers="headers" field-name="uploadFile" label="文件上传" @uploaded="uploadResult" color="purple" square flat bordered style="max-width: 300px" />
                        </div> -->
                        <div class="q-video" style="margin-top: 10px" v-if="form.viedoUrl">
                            <iframe :src="form.viedoUrl" frameborder="0" allowfullscreen />
                        </div>
                        <div class="col-12" style="margin-top: 10px">
                            <q-btn color="primary" icon="mdi-delete" label="删除" outline class="q-mx-md" @click="delVideo" v-if="form.viedoUrl" />
                        </div>
                    </div>
                </q-scroll-area>
                <div class="row justify-center q-pa-md">
                    <q-btn outline color="primary" icon="mdi-close-thick" label="关闭" v-close-popup />
                    <q-btn class="q-mx-md" color="primary" icon="mdi-check-bold" label="提交" :loading="loading" type="submit" />
                </div>
            </q-form>
        </q-dialog>
        <q-dialog maximized flat persistent ref="EchartsDialog">
            <q-form class="dialog_card column">
                <h5 class="view_title justify-between q-px-md">
                    错题分布
                    <q-btn dense outline round icon="clear" size="sm" v-close-popup />
                </h5>
                <q-scroll-area class="col">
                    <echartsBar ref="echartsBarview"></echartsBar>

                </q-scroll-area>
                <div class="row justify-center q-pa-md">
                    <q-btn outline color="primary" icon="mdi-close-thick" label="关闭" v-close-popup />
                </div>
            </q-form>
        </q-dialog>
        <confirm ref="confirmDialog" :msg="confirmMsg" @confirm="deleteBatch()" />
        <q-inner-loading :showing="loading">
            <q-spinner-gears size="50px" color="primary" />
        </q-inner-loading>
    </q-page>
</template>

<script>
import { IndexMixin } from 'boot/mixins';
import { getDictLabel } from 'boot/dictionary';
import confirm from 'components/confirm';
import 'katex/dist/katex.min.css';
import katex from 'katex';
import echartsBar from 'src/pages/postgraduate/echarts/echarts-bar.vue';

export default {
  name: 'BlankErrorQuestions',
  mixins: [IndexMixin],
  components: {
    confirm,
    echartsBar,

  },
  data() {
    return {
      catalog: '01',
      form: {
        question: '',
        id: '',
        answer: '',
        studentAnswer: '',
        analysis: '',
      },
      columns: [
        {
          name: 'index',
          align: 'center',
          label: '序号',
          field: 'index',
        },
        {
          name: 'majorText',
          align: 'center',
          label: '专业',
          field: 'majorText',
        },
        {
          name: 'question',
          align: 'center',
          label: '题目',
          field: 'question',
        },
        {
          name: 'opt', align: 'center', label: '操作', field: 'id',
        },
      ],
      showQuery: true,
      headers: [{ name: 'Authorization', value: localStorage.Authorization }],
      uploadUrl: `${process.env.SERVER_URL}${process.env.BASE_URL}/sys/common/upload`,
      imgUrl: `${process.env.SERVER_URL}${process.env.BASE_URL}/sys/common/static`,
      url: {
        list: '/blank/errorQuestions/list',
        add: '/blank/errorQuestions/add',
        edit: '/blank/errorQuestions/edit',
        copy:
                    '/blank/errorQuestions/copy',
        delete: '/blank/errorQuestions/delete',
        deleteBatch: '/blank/errorQuestions/deleteBatch',
        exportXlsUrl: '/blank/errorQuestions/exportXls',
        importExcelUrl: '/blank/errorQuestions/importExcel',
      },
    };
  },
  methods: {
    viewEcharts() {
      this.$refs.EchartsDialog.show();
      this.$nextTick(() => {
        this.$refs.echartsBarview.show(this.list);
      });
    },
    renderMath(str) {
      return katex.renderToString(str, {
        throwOnError: false,
      });
    },
    getDictLabel,

    initDict() {
    },
  },
  mounted() {
    this.initDict();
  },
};
</script>

<style lang="stylus">

</style>
